package context;

import factory.BeanDefinitionRegisty;
import factory.ConfigurableListableBeanFactory;
import factory.DefaultListableBeanFactory;

/**
 * Created by inuyasha on 18-3-22.
 */
public abstract class AbstractApplicationContext implements ApplicationContext{
    private ConfigurableListableBeanFactory beanFactory;

    public Object getBean(String name) {
        return beanFactory.getBean(name);
    }

    public void refresh() throws Exception {
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
        loadBeanDefinition(beanFactory);
        this.beanFactory = beanFactory;
        onRefresh();
    }

    public void onRefresh() throws Exception{
        beanFactory.preInstantiateSingletons();
    }

    protected abstract void loadBeanDefinition(BeanDefinitionRegisty registy) throws  Exception;
}
